﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business;
using System.Data;
using SqliteDataAccess;

namespace MVP
{
    public class ProfilPresenter : BasePresenter<IProfilView>
    {
        private IProfilView _view;
        private ProfilBusiness _business
        {
            get { return (ProfilBusiness)Business; }
        }
        public ProfilPresenter(IProfilView view)
            : base(view)
        {
            _view = view;
            Business = new ProfilBusiness();
            _view.Save += OnViewSave;
        }
        private void OnViewSave(object sender, EventArgs e)
        {
            SqliteDataManager.ProfilSekolahRow profil = _business.GetProfil();
            profil.yayasan = _view.Yayasan;
            profil.ketua_yayasan = _view.KetuaYayasan;
            profil.sekolah = _view.Sekolah;
            profil.kepala_sekolah = _view.KepalaSekolah;
            profil.bendahara_sekolah = _view.BendaharaSekolah;
            _business.Save(profil);
            //_view.SendMessageInfo("Saved.");
        }

        protected override void OnViewInitialize(object sender, EventArgs e)
        {
            SqliteDataManager.ProfilSekolahRow profil = _business.GetProfil();
            if (!profil.IsNull("Id"))
            {
                _view.Yayasan = profil.IsyayasanNull() ? "" : profil.yayasan;
                _view.KetuaYayasan = profil.Isketua_yayasanNull() ? "" : profil.ketua_yayasan;
                _view.Sekolah = profil.IssekolahNull() ? "" : profil.sekolah;
                _view.KepalaSekolah = profil.Iskepala_sekolahNull() ? "" : profil.kepala_sekolah;
                _view.BendaharaSekolah = profil.Isbendahara_sekolahNull() ? "" : profil.bendahara_sekolah;
            }
        }
    }
}
